package com.heima.wemedia.controller.v1;

import com.heima.common.wemedia.WemediaConstants;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.WmMaterialDTO;
import com.heima.wemedia.service.WmMaterialService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@Api(value = "素材管理",tags = "素材管理")
@RestController
@RequestMapping("/api/v1/material")
public class wmMaterialController {

    @Autowired
    private WmMaterialService wmMaterialService;

    @ApiOperation("素材上传")
    @PostMapping("/upload_picture")
    public ResponseResult uploadPicture(MultipartFile multipartFile){
        return wmMaterialService.uploadPicture(multipartFile);
    }

    @ApiOperation("分页查询素材")
    @PostMapping("/list")
    public ResponseResult list(@RequestBody WmMaterialDTO dto){
        return wmMaterialService.findList(dto);
    }

    @ApiOperation("素材删除")
    @GetMapping("/del_picture/{id}")
    public ResponseResult deletePic(@PathVariable("id") Integer id){
        return wmMaterialService.delPic(id);
    }
    @ApiOperation("素材收藏")
    @GetMapping("/collect/{id}")
    public ResponseResult collect(@PathVariable("id") Integer id){
        return wmMaterialService.collect(id, WemediaConstants.COLLECT_MATERIAL);
    }

    @ApiOperation("素材取消收藏")
    @GetMapping("/cancel_collect/{id}")
    public ResponseResult cancel_collect(@PathVariable("id") Integer id){
        return wmMaterialService.collect(id, WemediaConstants.CANCEL_COLLECT_MATERIAL);
    }
}
